package com.xxz.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import javax.servlet.http.HttpSession;

@Controller
public class LoginController {
    @RequestMapping("/login")// 点击登录就要跳进这个请求里面
    public String login(@RequestParam("username") String username,
                        @RequestParam("password") String password,
                        Model model,
                        HttpSession session) {
        //业务  写非空和密码判断
        if (!StringUtils.isEmpty(username) && "328".equals(password)) {
            session.setAttribute("loginUser", username);
            return "redirect:xxz";  //重定向到main也就跳转 dashboard页面 这样就不会暴露信息了 记得一定要去自定义视图controller中修改
        } else {
            // 回显错误信息
            model.addAttribute("msg", "账号或者密码错误");
            return "index";
        }
    }
}